package SpringProject.Utils;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class RedisTemplateUtils {
    @Autowired
    private RedisTemplate redisTemplate;

    public <T> T get(String key, Class<T> clazz) {
        return (T) redisTemplate.opsForValue().get(key);
    }

    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public void set(String key, Object data) {
        redisTemplate.opsForValue().set(key, data);
    }

    public Set<String> keys(String pattern) {
        DataType type = redisTemplate.type("");
        Set keys = redisTemplate.keys(pattern);
        return keys;
    }
    public void hSet(String key,String hashKey, Object data) {
        redisTemplate.opsForHash().put(key,hashKey,data);
    }

    public Object hGet(String key,String hashKey) {
        return redisTemplate.opsForHash().get(key,hashKey);
    }
}
